*******************************************************************************
* Load candidates data
*******************************************************************************

use dataset_candidates, clear

*******************************************************************************
* Do the regressions for the full sample
*******************************************************************************

eststo clear
eststo: reg ideology deputy, cl(district)
eststo: reg ideology deputy support, cl(district)
eststo: areg ideology deputy cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology deputy support cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"

*******************************************************************************
* Output
*******************************************************************************

label variable deputy "Experienced"
label variable support "Constituency Conservatism"

#delimit;

esttab
	using "_output/tableS3_a.tex"
	,
		replace
		booktabs
		cells(b(fmt(3)) se(par) p(par("[" "]")))
		drop(cycle*) 
		stats(
			N cyclefe statefe,
			label(
				"Observations"
				"State fixed effects"
				"Cycle fixed effects"
			)
			fmt(%20.0f %20.0f)
		)
		label
		collabels(none)	
		mlabels(none)
		width(\linewidth)
		alignment(l)
		gap
		;
		
#delimit cr

*******************************************************************************
* Do the regressions for the sample with partisanship
*******************************************************************************

keep if !mi(party)

eststo clear
eststo: reg ideology deputy, cl(district)
eststo: reg ideology party_2-party_3, cl(district)
eststo: reg ideology deputy party_2-party_3 support, cl(district)
eststo: areg ideology deputy cycle_*, cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology party_2-party_3 cycle_*, ///
	cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"
eststo: areg ideology deputy party_2-party_3 cycle_* support, ///
	cl(district) a(state)
estadd local cyclefe = "X"
estadd local statefe = "X"


*******************************************************************************
* Output
*******************************************************************************

label variable party_2 "Independent"
label variable party_3 "Republican"

#delimit;

esttab
	using "_output/tableS3_b.tex"
	,
		replace
		booktabs
		cells(b(fmt(3)) se(par) p(par("[" "]")))
		drop(cycle*) 
		stats(
			N cyclefe statefe,
			label(
				"Observations"
				"State fixed effects"
				"Cycle fixed effects"
			)
			fmt(%20.0f %20.0f)
		)
		label
		collabels(none)	
		mlabels(none)
		width(\linewidth)
		alignment(l)
		gap
		;
		
#delimit cr

*******************************************************************************
* End
*******************************************************************************
